package com.java10_13_4;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        // 创建集合对象
        List<Student> list = new ArrayList<Student>();

        // 创建学生对象
        Student s1 = new Student("张三", 20);
        Student s2 = new Student("李四", 20);
        Student s3 = new Student("王五", 30);

        // 添加学生对象
        list.add(s1);
        list.add(s2);
        list.add(s3);

        System.out.println(list);

        // 迭代器方式
        Iterator<Student> it = list.iterator();
        while(it.hasNext()) {
            Student s = it.next();
            System.out.println(s.getName() + "," + s.getAge());
        }
        System.out.println("---------------------------------");
        // for循环方式
        for (int i = 0; i < list.size(); i++) {
            Student s = list.get(i);
            System.out.println(s.getName() + "," + s.getAge());
        }
    }
}
